home *** CD-ROM | disk | FTP | other *** search
- /*LINTLIBRARY*/
-
- /* @(#)sunview.c 1.20 91/11/13
- *
- * SunView dependent graphics routines used by reve.
- *
- * Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
- * All rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include "reve.h"
- #include "color.h"
- #include "extern.h"
- #include "images.h"
- #include <sys/file.h>
- #include <sys/ioctl.h>
- #include <sys/wait.h>
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
-
- enum gr_type gtype = GSUNVIEW ; /* Graphics type. */
-
- #define CLIENT_NO 10
-
- #define CURSOR_SET (void) cursor_set
- #define ICON_SET (void) icon_set
- #define MENU_SET (void) menu_set
- #define PW_LOCK (void) pw_lock
- #define PW_ROP (void) pw_rop
- #define PW_SETCMSNAME (void) pw_setcmsname
- #define PW_STENCIL (void) pw_stencil
- #define PW_PUTCOLORMAP (void) pw_putcolormap
- #define PW_REVERSEVIDEO (void) pw_reversevideo
- #define PW_TTEXT (void) pw_ttext
- #define PW_UNLOCK (void) pw_unlock
- #define PW_VECTOR (void) pw_vector
- #define PW_WRITEBACKGROUND (void) pw_writebackground
- #define WIN_BELL (void) win_bell
- #define WINDOW_DONE (void) window_done
- #define WINDOW_SET (void) window_set
-
- #define BOARDFONT "/usr/lib/fonts/fixedwidthfonts/cour.r.10"
- #define BOLDFONT "/usr/lib/fonts/fixedwidthfonts/screen.b.12"
- #define HELPFONT "/usr/lib/fonts/fixedwidthfonts/cour.r.10"
- #define NORMALFONT "/usr/lib/fonts/fixedwidthfonts/screen.r.12"
-
- #define ROOT_NAME "/dev/win0"
-
- Pixrect *hglass_pr, *icon_pr, *nocur_pr ;
-
- Canvas ccanvas, gcanvas, hcanvas, pcanvas ;
- Cursor cursor[MAXCURSORS] ;
- Event *cur_event ;
- Frame cframe, gframe, hframe, pframe ;
- Icon reve_icon ;
-
- Notify_client client = (Notify_client) CLIENT_NO ;
-
- static void canvas_proc P((Canvas, Event *)) ;
- static void load_colors P(()) ;
-
- static Notify_value check_clock P((Notify_client, int)) ;
- static Notify_value quit_proc P((Notify_client, Destroy_status)) ;
- static Notify_value read_from_fd P((Notify_client, int)) ;
- static Notify_value sigchldcatcher P((Notify_client, int,
- union wait *, struct rusage *)) ;
- static Pixfont *get_font P((char *)) ;
- static Pixrect *load_image P((int, int, unsigned char *)) ;
- static Pixwin *get_wtype P((enum win_type)) ;
-
- Pixfont *font[MAXFONTS] ;
- Pixrect *images[MAXIMAGES] ;
- Pixwin *cpw, *gpw, *hpw, *ppw ;
-
- void pw_batch() ;
- int opvals[3] ; /* Pixrect rasterop values. */
- int pid ;
- static int rootfd ;
-
- /* 256-byte table for quickly reversing the bits in an unsigned 8-bit char,
- * used to convert between MSBFirst and LSBFirst image formats.
- */
-
- char revtable[256] = {
- 0, -128, 64, -64, 32, -96, 96, -32,
- 16, -112, 80, -48, 48, -80, 112, -16,
- 8, -120, 72, -56, 40, -88, 104, -24,
- 24, -104, 88, -40, 56, -72, 120, -8,
- 4, -124, 68, -60, 36, -92, 100, -28,
- 20, -108, 84, -44, 52, -76, 116, -12,
- 12, -116, 76, -52, 44, -84, 108, -20,
- 28, -100, 92, -36, 60, -68, 124, -4,
- 2, -126, 66, -62, 34, -94, 98, -30,
- 18, -110, 82, -46, 50, -78, 114, -14,
- 10, -118, 74, -54, 42, -86, 106, -22,
- 26, -102, 90, -38, 58, -70, 122, -6,
- 6, -122, 70, -58, 38, -90, 102, -26,
- 22, -106, 86, -42, 54, -74, 118, -10,
- 14, -114, 78, -50, 46, -82, 110, -18,
- 30, -98, 94, -34, 62, -66, 126, -2,
- 1, -127, 65, -63, 33, -95, 97, -31,
- 17, -111, 81, -47, 49, -79, 113, -15,
- 9, -119, 73, -55, 41, -87, 105, -23,
- 25, -103, 89, -39, 57, -71, 121, -7,
- 5, -123, 69, -59, 37, -91, 101, -27,
- 21, -107, 85, -43, 53, -75, 117, -11,
- 13, -115, 77, -51, 45, -83, 109, -19,
- 29, -99, 93, -35, 61, -67, 125, -3,
- 3, -125, 67, -61, 35, -93, 99, -29,
- 19, -109, 83, -45, 51, -77, 115, -13,
- 11, -117, 75, -53, 43, -85, 107, -21,
- 27, -101, 91, -37, 59, -69, 123, -5,
- 7, -121, 71, -57, 39, -89, 103, -25,
- 23, -105, 87, -41, 55, -73, 119, -9,
- 15, -113, 79, -49, 47, -81, 111, -17,
- 31, -97, 95, -33, 63, -65, 127, -1,
- } ;
-
- void
- batch(state) /* Turn graphics batching on or off. */
- enum bltype state ;
- {
- switch (state)
- {
- case IS_ON : pw_batch_on(cpw) ;
- break ;
- case IS_OFF : pw_batch_off(cpw) ;
- }
- }
-
-
- void
- beep()
- {
- static struct timeval btime = { 0, 250000 } ; /* Beep timer. */
- int bfd ; /* File descriptor for reve window. */
-
- bfd = (int) window_get(gframe, WIN_FD) ;
- WIN_BELL(bfd, btime, 0) ;
- }
-
-
- /*ARGSUSED*/
- static void
- canvas_proc(c, event)
- Canvas c ;
- Event *event ;
- {
- if (c == ccanvas) curwin = W_PANEL ;
- else if (c == gcanvas) curwin = W_BOARD ;
- else if (c == hcanvas) curwin = W_HELP ;
- else if (c == pcanvas) curwin = W_PROPS ;
-
- cur_event = event ; /* Determine what kind of event it is. */
- handle_event() ; /* And do the appropriate action. */
- update_clock(next_player, FALSE) ;
- }
-
-
- static Notify_value
- check_clock(client, itimer_type)
- Notify_client client ;
- int itimer_type ;
- {
- update_clock(next_player, FALSE) ;
- return(NOTIFY_DONE) ;
- }
-
-
- void
- close_reve()
- {
- WINDOW_SET(gframe, FRAME_CLOSED, TRUE, 0) ;
- }
-
-
- void
- color_area(wtype, x, y, width, height, color)
- enum win_type wtype ;
- int x, y, width, height, color ;
- {
- Pixwin *pw = get_wtype(wtype) ;
-
- PW_WRITEBACKGROUND(pw, x, y, width, height, PIX_SRC | PIX_COLOR(color)) ;
- }
-
-
- void
- connect_io() /* Connect to computer process and possible remote human. */
- {
- if (pipe_io[1][0] > 0)
- notify_set_input_func(client, read_from_fd, pipe_io[1][0]) ;
- if (socketfd > 0)
- notify_set_input_func(client, read_from_fd, socketfd) ;
- notify_set_wait3_func(client, sigchldcatcher, pid) ;
- }
-
-
- void
- destroy_reve() /* Terminate Reve. */
- {
- window_destroy(cframe) ;
- window_destroy(gframe) ;
- KILL(pid, SIGKILL) ;
- exit(0) ;
- }
-
-
- void
- draw_image(wtype, x, y, width, height, image)
- enum win_type wtype ;
- int x, y, width, height ;
- enum image_type image ;
- {
- Pixwin *pw = get_wtype(wtype) ;
-
- PW_ROP(pw, x, y, width, height, PIX_SRC | PIX_DST,
- images[(int) image], 0, 0) ;
- }
-
-
- void
- draw_line(wtype, x1, y1, x2, y2, op, color)
- enum win_type wtype ;
- int x1, y1, x2, y2, color ;
- enum optype op ;
- {
- int rop ;
- Pixwin *pw = get_wtype(wtype) ;
-
- rop = opvals[(int) op] ;
- if (!iscolor && color == C_WHITE) rop = opvals[(int) RCLR] ;
- PW_VECTOR(pw, x1, y1, x2, y2, rop | PIX_COLOR(color), 1) ;
- }
-
-
- void
- draw_stencil(wtype, x, y, width, height, op, color, stencil, image)
- enum win_type wtype ;
- int x, y, width, height, color ;
- enum optype op ;
- enum image_type stencil, image ;
- {
- int rop ;
- Pixwin *pw = get_wtype(wtype) ;
-
- rop = opvals[(int) op] | PIX_COLOR(color) ;
- PW_STENCIL(pw, x, y, width, height, rop,
- images[(int) stencil], 0, 0, images[(int) image], 0, 0) ;
- }
-
-
- void
- draw_text(wtype, x, y, ftype, color, str)
- enum win_type wtype ;
- enum font_type ftype ;
- int x, y, color ;
- char *str ;
- {
- Pixwin *pw = get_wtype(wtype) ;
-
- PW_TTEXT(pw, x, y, PIX_SRC | PIX_COLOR(color), font[(int) ftype], str) ;
- }
-
-
- static Pixfont *
- get_font(name)
- char *name ;
- {
- Pixfont *f ;
-
- f = pf_open(name) ;
- if (f == NULL) f = pf_default() ;
- if (f == NULL)
- {
- perror("couldn't get the default font.") ;
- exit(1) ;
- }
- return f ;
- }
-
-
- /*ARGSUSED*/
- char *
- get_resource(rtype) /* Null routine (currently only X11 and XView). */
- enum res_type rtype ;
- {
- return((char *) NULL) ;
- }
-
-
- int
- get_strwidth(ftype, str) /* Get width in pixels of string value. */
- enum font_type ftype ;
- char *str ;
- {
- struct pr_size size ;
-
- size = pf_textwidth(strlen(str), font[(int) ftype], str) ;
- return(size.x) ;
- }
-
-
- static Pixwin *
- get_wtype(wtype)
- enum win_type wtype ;
- {
- if (wtype == W_PANEL) return(cpw) ;
- else if (wtype == W_BOARD) return(gpw) ;
- else if (wtype == W_HELP) return(hpw) ;
- else if (wtype == W_PROPS) return(ppw) ;
- }
-
-
- void
- init_fonts() /* Open the normal and bold fonts. */
- {
- int i ;
-
- font[(int) BFONT] = get_font(BOLDFONT) ;
- font[(int) GFONT] = get_font(BOARDFONT) ;
- font[(int) HFONT] = get_font(HELPFONT) ;
- font[(int) NFONT] = get_font(NORMALFONT) ;
-
- for (i = 0; i < MAXFONTS; i++)
- font_heights[i] = font[i]->pf_defaultsize.y ;
- }
-
-
- /*ARGSUSED*/
- void
- init_graphics(argc, argv)
- int *argc ;
- char *argv[] ;
- {
- images[(int) BUT_STENCIL] = load_image(64, 64, Sbutton_bits) ;
- images[(int) BUT_INVERT] = load_image(64, 64, Ibutton_bits) ;
- images[(int) BUT_NORMAL] = load_image(64, 64, Nbutton_bits) ;
- images[(int) CY_NORMAL] = load_image(64, 64, Ncycle_bits) ;
- images[(int) CY_STENCIL] = load_image(64, 64, Scycle_bits) ;
- images[(int) CY_LINVERT] = load_image(64, 64, Lcycle_bits) ;
- images[(int) CY_RINVERT] = load_image(64, 64, Rcycle_bits) ;
- icon_pr = load_image(64, 64, reve_bits) ;
- images[(int) TOGGLE_OFF] = load_image(64, 64, Sch_off_bits) ;
- images[(int) TOGGLE_ON] = load_image(64, 64, Sch_on_bits) ;
- images[(int) P_WHITE] = load_image(64, 64, white_bits) ;
- images[(int) P_BLACK] = load_image(64, 64, black_bits) ;
- images[(int) S_MOVE] = load_image(64, 64, move_bits) ;
- images[(int) S_SUGGEST] = load_image(64, 64, suggest_bits) ;
-
- hglass_pr = load_image(16, 16, hglass_bits) ;
- nocur_pr = load_image(16, 16, nocur_bits) ;
- }
-
-
- int
- init_ws_type()
- {
- if (getenv("WINDOW_PARENT") == NULL)
- {
- FPRINTF(stderr,"%s: Not a native SunView window\n", progname) ;
- return(-1) ;
- }
- gtype = GSUNVIEW ; /* Graphics type. */
- move_delta = 5 ; /* Delta for computer animate move. */
- rootfd = open(ROOT_NAME, O_RDONLY, 0) ;
- return(0) ;
- }
-
-
- static void
- load_colors() /* Create and load reve color map. */
- {
- Pixwin *frame_pw ;
- unsigned char r[REVE_COLORSIZE], g[REVE_COLORSIZE], b[REVE_COLORSIZE] ;
- char colorname[CMS_NAMESIZE] ;
- int i ;
-
- for (i = 0; i < REVE_COLORSIZE; i++)
- {
- r[i] = (unsigned char) rcols[i] ;
- g[i] = (unsigned char) gcols[i] ;
- b[i] = (unsigned char) bcols[i] ;
- }
-
- iscolor = (cpw->pw_pixrect->pr_depth == 8) ? 1 : 0 ;
- if (iscolor)
- {
- SPRINTF(colorname, "%s%D", REVE_COLOR, getpid()) ;
- PW_SETCMSNAME(cpw, colorname) ;
-
- PW_PUTCOLORMAP(cpw, 0, REVE_COLORSIZE, r, g, b) ;
- }
- if (inv_video) PW_REVERSEVIDEO(cpw, 0, REVE_COLORSIZE) ;
-
- if (iscolor)
- {
- Pixwin *frame_pw ;
-
- frame_pw = (Pixwin *) window_get(gframe, WIN_PIXWIN) ;
- PW_SETCMSNAME(frame_pw, colorname) ;
- PW_PUTCOLORMAP(frame_pw, 0, REVE_COLORSIZE, r, g, b) ;
-
- PW_SETCMSNAME(gpw, colorname) ;
- PW_PUTCOLORMAP(gpw, 0, REVE_COLORSIZE, r, g, b) ;
-
- PW_SETCMSNAME(hpw, colorname) ;
- PW_PUTCOLORMAP(hpw, 0, REVE_COLORSIZE, r, g, b) ;
-
- PW_SETCMSNAME(ppw, colorname) ;
- PW_PUTCOLORMAP(ppw, 0, REVE_COLORSIZE, r, g, b) ;
- }
- }
-
-
- static Pixrect *
- load_image(width, height, cbuf)
- int width, height ;
- unsigned char cbuf[] ;
- {
- int i, j, llen ;
- unsigned short *sbuf ;
-
- llen = (width * height) / 16 ;
- sbuf = (unsigned short *) malloc((unsigned int) (llen * 2)) ;
- for (i = 0; i < llen; i++)
- sbuf[i] = (revtable[cbuf[(i*2)+1]] & 0xFF) +
- ((revtable[cbuf[i*2]] & 0xFF) << 8) ;
-
- return(mem_point(width, height, 1, sbuf)) ;
- }
-
-
- void
- load_resources() /* Dummy routine; used with X11 and XView versions. */
- {
- }
-
-
- void
- lock_screen(state) /* Turn graphics locking on or off. */
- enum bltype state ;
- {
- static struct rect r = { 0, 0, 0, 0 } ;
-
- r.r_width = board_width ;
- r.r_height = board_height ;
- switch (state)
- {
- case IS_ON : PW_LOCK(gpw, &r) ;
- break ;
- case IS_OFF : PW_UNLOCK(gpw) ;
- }
- }
-
-
- void
- make_canvas() /* Create canvas for game board. */
- {
- ccanvas = window_create(cframe, CANVAS,
- CANVAS_RETAINED, FALSE,
- WIN_HEIGHT, PANEL_HEIGHT,
- WIN_WIDTH, PANEL_WIDTH,
- WIN_CONSUME_PICK_EVENTS,
- MS_LEFT, MS_MIDDLE,
- LOC_MOVE, LOC_DRAG, LOC_TRAJECTORY,
- LOC_WINENTER, LOC_WINEXIT,
- 0,
- WIN_CONSUME_KBD_EVENTS,
- KBD_USE, KBD_DONE, WIN_ASCII_EVENTS, WIN_UP_EVENTS,
- 0,
- WIN_EVENT_PROC, canvas_proc,
- 0) ;
- cpw = (Pixwin *) window_get(ccanvas, CANVAS_PIXWIN) ;
- if (inv_video) PW_REVERSEVIDEO(cpw, 0, REVE_COLORSIZE) ;
-
- gcanvas = window_create(gframe, CANVAS,
- CANVAS_RETAINED, FALSE,
- WIN_HEIGHT, BOARD_DIM,
- WIN_WIDTH, BOARD_DIM,
- WIN_CONSUME_PICK_EVENTS,
- MS_LEFT, MS_MIDDLE,
- 0,
- WIN_CONSUME_KBD_EVENTS,
- KBD_USE, KBD_DONE, WIN_ASCII_EVENTS, WIN_UP_EVENTS,
- 0,
- WIN_EVENT_PROC, canvas_proc,
- 0) ;
- gpw = (Pixwin *) window_get(gcanvas, CANVAS_PIXWIN) ;
- if (inv_video) PW_REVERSEVIDEO(gpw, 0, REVE_COLORSIZE) ;
-
- pcanvas = window_create(pframe, CANVAS,
- CANVAS_RETAINED, FALSE,
- WIN_HEIGHT, PROPS_HEIGHT,
- WIN_WIDTH, PROPS_WIDTH,
- WIN_CONSUME_PICK_EVENTS,
- MS_LEFT, MS_MIDDLE,
- 0,
- WIN_CONSUME_KBD_EVENTS,
- KBD_USE, KBD_DONE, WIN_ASCII_EVENTS, WIN_UP_EVENTS,
- 0,
- WIN_EVENT_PROC, canvas_proc,
- 0) ;
- ppw = (Pixwin *) window_get(pcanvas, CANVAS_PIXWIN) ;
- if (inv_video) PW_REVERSEVIDEO(ppw, 0, REVE_COLORSIZE) ;
-
- cursor[(int) CANVASCUR] = window_get(gcanvas, WIN_CURSOR) ;
- CURSOR_SET(cursor[(int) CANVASCUR], CURSOR_OP, PIX_SRC ^ PIX_DST, 0) ;
- cursor[(int) HOURGLASS] = cursor_create(CURSOR_IMAGE, &hglass_pr, 0) ;
- CURSOR_SET(cursor[(int) HOURGLASS], CURSOR_OP, PIX_SRC ^ PIX_DST, 0) ;
- cursor[(int) NOCURSOR] = cursor_create(CURSOR_IMAGE, &nocur_pr, 0) ;
- CURSOR_SET(cursor[(int) NOCURSOR], CURSOR_OP, PIX_SRC ^ PIX_DST, 0) ;
- if (!monochrome) load_colors() ;
-
- pid = fork_child() ;
- }
-
-
- void
- make_frame(argc, argv) /* Create reve window. */
- int argc ;
- char *argv[] ;
- {
- opvals[(int) RCLR] = PIX_CLR ;
- opvals[(int) RSRC] = PIX_SRC ;
- opvals[(int) RINV] = PIX_SRC ^ PIX_DST ;
-
- gframe = window_create((Window) NULL, FRAME,
- FRAME_ICON, reve_icon,
- FRAME_LABEL, "reve game board",
- FRAME_NO_CONFIRM, TRUE,
- WIN_ERROR_MSG, "Can't create window.",
- WIN_X, 0,
- WIN_Y, 0,
- FRAME_ARGS, argc, argv,
- 0) ;
-
- cframe = window_create((Window) NULL, FRAME,
- FRAME_ICON, reve_icon,
- FRAME_LABEL, line,
- FRAME_NO_CONFIRM, TRUE,
- WIN_ERROR_MSG, "Can't create window.",
- WIN_BELOW, gframe,
- WIN_SHOW, TRUE,
- FRAME_ARGS, argc, argv,
- 0) ;
-
- pframe = window_create(gframe, FRAME,
- FRAME_LABEL, "reve properties",
- FRAME_NO_CONFIRM, TRUE,
- WIN_ERROR_MSG, "Can't create window.",
- WIN_RIGHT_OF, gframe,
- WIN_SHOW, FALSE,
- FRAME_ARGS, argc, argv,
- 0) ;
- }
-
-
- void
- make_help_window(argc, argv)
- int argc ;
- char *argv[] ;
- {
- int fontwidth ;
-
- hframe = window_create(gframe, FRAME,
- FRAME_LABEL, "reve help",
- FRAME_NO_CONFIRM, TRUE,
- WIN_ERROR_MSG, "Can't create window.",
- WIN_RIGHT_OF, gframe,
- WIN_SHOW, FALSE,
- FRAME_ARGS, argc, argv,
- 0) ;
-
- fontwidth = font[(int) HFONT]->pf_defaultsize.x ;
- help_height = ((font_heights[(int) HFONT] + 1) * HELP_ROWS) +
- (4 * CGAP) + CHEIGHT ;
- help_width = (fontwidth * HELP_COLS) + (2 * CGAP) ;
-
- hcanvas = window_create(hframe, CANVAS,
- CANVAS_RETAINED, FALSE,
- WIN_HEIGHT, help_height,
- WIN_WIDTH, help_width,
- WIN_CONSUME_PICK_EVENTS,
- MS_LEFT, MS_MIDDLE,
- 0,
- WIN_CONSUME_KBD_EVENTS,
- KBD_USE, KBD_DONE, WIN_ASCII_EVENTS, WIN_UP_EVENTS,
- 0,
- WIN_EVENT_PROC, canvas_proc,
- 0) ;
- hpw = (Pixwin *) window_get(hcanvas, CANVAS_PIXWIN) ;
- if (inv_video) PW_REVERSEVIDEO(hpw, 0, REVE_COLORSIZE) ;
- }
-
-
- void
- make_icon()
- {
- reve_icon = icon_create(ICON_IMAGE, icon_pr, 0) ;
- }
-
-
- void
- make_pieces(width, height)
- int width, height ;
- {
- bborder = BBORDER ;
-
- cell_width = (width - (2 * bborder)) / BOARD_SIZE ;
- cell_height = (height - (2 * bborder)) / BOARD_SIZE ;
-
- pieceXmargin = cell_width / 8 ;
- pieceYmargin = cell_height / 8 ;
-
- pieceXrad = (cell_width - (2 * pieceXmargin)) / 2 ;
- if (pieceXrad > MAXPRAD)
- {
- pieceXrad = MAXPRAD ;
- pieceXmargin = (cell_width - (2 * pieceXrad)) / 2 ;
- }
-
- pieceYrad = (cell_height - (2 * pieceYmargin)) / 2 ;
- if (pieceYrad > MAXPRAD)
- {
- pieceYrad = MAXPRAD ;
- pieceYmargin = (cell_height - (2 * pieceYrad)) / 2 ;
- }
- }
-
-
- void
- open_reve()
- {
- WINDOW_SET(gframe, FRAME_CLOSED, FALSE, 0) ;
- }
-
-
- void
- process_event() /* Process the next canvas event. */
- {
- int id ;
-
- id = (event_id(cur_event)) ;
- curx = event_x(cur_event) ;
- cury = event_y(cur_event) ;
-
- if (event_is_button(cur_event) && event_is_down(cur_event))
- {
- if (id == MS_LEFT) nextc = LEFT_DOWN ;
- else if (id == MS_MIDDLE) nextc = MIDDLE_DOWN ;
- else if (id == MS_RIGHT) nextc = RIGHT_DOWN ;
- }
- else if (event_is_button(cur_event) && event_is_up(cur_event))
- {
- if (id == MS_LEFT) nextc = LEFT_UP ;
- else if (id == MS_MIDDLE) nextc = MIDDLE_UP ;
- else if (id == MS_RIGHT) nextc = RIGHT_UP ;
- }
- else if (event_is_ascii(cur_event))
- {
- cur_ch = id ;
- nextc = KEYBOARD ;
- }
- else if (id == KBD_DONE || id == LOC_WINEXIT ||
- id == WIN_STOP || id == LOC_RGNEXIT) nextc = EXIT_WINDOW ;
- else if (id == LOC_WINENTER || id == LOC_RGNENTER) nextc = ENTER_WINDOW ;
- else if (processing == FALSE &&
- (id == LOC_MOVE || id == LOC_DRAG || id == LOC_TRAJECTORY))
- nextc = MOUSE_MOVING ;
- else if (id == WIN_REPAINT)
- {
- if (curwin == W_PANEL) nextc = PANEL_REPAINT ;
- else if (curwin == W_BOARD) nextc = BOARD_REPAINT ;
- else if (curwin == W_HELP) nextc = HELP_REPAINT ;
- else if (curwin == W_PROPS) nextc = PROPS_REPAINT ;
- }
- }
-
-
- static Notify_value
- quit_proc(client, status)
- Notify_client client ;
- Destroy_status status ;
- {
- KILL(pid, SIGKILL) ;
- exit(0) ;
- }
-
-
- void
- raise_reve()
- {
- wmgr_top((int) window_get(gframe, WIN_FD), rootfd) ;
- }
-
-
- static Notify_value
- read_from_fd(client, fd)
- Notify_client client ;
- register int fd ;
- {
- if (fd == socketfd) read_from_sock(fd) ; /* Remote human. */
- else if (fd == pipe_io[1][0]) read_from_reve(fd) ; /* Computer. */
- return(NOTIFY_DONE) ;
- }
-
-
- void
- set_cursor(ctype)
- enum curtype ctype ;
- {
- WINDOW_SET(ccanvas, WIN_CURSOR, cursor[(int) ctype], 0) ;
- WINDOW_SET(gcanvas, WIN_CURSOR, cursor[(int) ctype], 0) ;
- WINDOW_SET(hcanvas, WIN_CURSOR, cursor[(int) ctype], 0) ;
- WINDOW_SET(pcanvas, WIN_CURSOR, cursor[(int) ctype], 0) ;
- }
-
-
- void
- set_frame(wtype, showing)
- enum win_type wtype ;
- int showing ;
- {
- Frame f ;
-
- if (wtype == W_HELP) f = hframe ;
- else if (wtype == W_PROPS) f = pframe ;
- WINDOW_SET(f, WIN_SHOW, showing, 0) ;
- }
-
-
- static Notify_value
- sigchldcatcher(client, pid, status, rusage)
- Notify_client client ;
- int pid ;
- union wait *status ;
- struct rusage *rusage ;
- {
- if (WIFEXITED(*status))
- {
- notify_set_input_func(client, NOTIFY_FUNC_NULL, pipe_io[1][0]) ;
- return(NOTIFY_DONE) ;
- }
- return(NOTIFY_IGNORED) ;
- }
-
-
- /*ARGSUSED*/
- void
- start_tool(dtype) /* Display window and start the notifier. */
- enum disp_type dtype ;
- {
- struct itimerval tval ;
-
- tval.it_interval.tv_usec = 0 ; /* Force a timing check every second. */
- tval.it_interval.tv_sec = 1 ;
- tval.it_value.tv_usec = 0 ;
- tval.it_value.tv_sec = 1 ;
- notify_set_itimer_func(gframe, check_clock, ITIMER_REAL,
- &tval, (struct itimerval *) 0) ;
-
- window_fit(cframe) ;
- window_fit(gframe) ;
- window_fit(hframe) ;
- window_fit(pframe) ;
- notify_interpose_destroy_func(gframe, quit_proc) ;
- notify_interpose_destroy_func(cframe, quit_proc) ;
- window_main_loop(gframe) ;
- }
-